/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package main;

import java.text.ParseException;
import java.util.Date;
import job.CalculateTimeJob;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.SchedulerException;
import org.quartz.Trigger;
import quartz.JobBuilder;
import quartz.SchedulerManager;
import quartz.TriggerBuilder;

/**
 *
 * @author yjbian
 */
public class CronExample {

    /**
     * @throws java.text.ParseException
     * @throws org.quartz.SchedulerException
     */
    public static void testJobNoDataMap() throws ParseException, SchedulerException {

        JobDetail jobDetail = JobBuilder.buildJobDetail("CronJob001", "CronGroup", new CalculateTimeJob());

        String cronExpression = "5,15,25,35,45 * * * * ? ";
        Trigger trigger = TriggerBuilder.buildCronTrigger("CronTrigger001", cronExpression);
        SchedulerManager.scheduleJob(jobDetail, trigger);

    }

    public static void testJobWithDataMap() throws ParseException, SchedulerException {
        JobDataMap jobDataMap = new JobDataMap();
        jobDataMap.put("BaseTime", "2015-06-01 00:00:00");
        JobDetail jobDetail = JobBuilder.buildJobDetail("CronJob002", "CronGroup", new CalculateTimeJob(), jobDataMap);

        Date startTime = new Date();
        long endTimeValue = startTime.getTime() + 60 * 1000L;
        Date endTime = new Date(endTimeValue);
        
        String cronExpression = "0/5 * * * * ? ";
        Trigger trigger = TriggerBuilder.buildCronTrigger("CronTrigger002", startTime, endTime, cronExpression);

        SchedulerManager.scheduleJob(jobDetail, trigger);
    }
}
